function IEVersion()
{  
	var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
	var isOpera = userAgent.indexOf("Opera") > -1; //判断是否Opera浏览器  
	var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera; //判断是否IE浏览器  
	var isEdge = userAgent.indexOf("Windows NT 6.1; Trident/7.0;") > -1 && !isIE; //判断是否IE的Edge浏览器  
	if(isIE)  
	{  
		var reIE = new RegExp("MSIE (\\d+\\.\\d+);");  
		reIE.test(userAgent);  
		var fIEVersion = parseFloat(RegExp["$1"]);  
		if(fIEVersion == 7)  
		{ return 7;}  
		else if(fIEVersion == 8)  
		{ return 8;}  
		else if(fIEVersion == 9)  
		{ return 9;}  
		else if(fIEVersion == 10)  
		{ return 10;}  
		else if(fIEVersion == 11)  
		{ return 11;}  
		else  
		{ return 0}//IE版本过低  
	}  
	else if(isEdge)  
	{  
		return 20;  
	}  
	else  
	{  
		return -1;//非IE  
	}  
}  
var iever = IEVersion();
if(iever == 8 || iever == 7)
{
	alert("为了更好体验本站，请使用IE9及以上版本或其他浏览器（如：360,火狐）");	
}

var _Url = decodeURI(location.href);
var Refer = decodeURI(document.referrer);
var istrues = true,t = new Date().getTime();

var csrfdata = $.ajax({url:"/error/setcrsf",async:false});
    $("#_csrf").val(csrfdata.responseText)
    $('meta[name="csrf-token"]').attr("content",csrfdata.responseText);
var csrfToken = csrfdata.responseText || $("#_csrf").val() || $('meta[name="csrf-token"]').attr("content");

function background(o){
    var o = o || {},
        zIndex = o.zindex || 999999,
        width = Math.max(document.body.clientWidth || document.documentElement.clientWidth) + 'px',
        height = Math.max(document.body.clientHeight || document.documentElement.clientHeight ) + 'px',
       // height = '3000px',
        iframe = !$('#sb86backgroundBoardId').length ? $('<iframe id="sb86backgroundBoardId" scrolling="no" frameborder="0" \
                    style="overflow:hidden; \
                        position:absolute; \
                        background:#000; \
                        z-index:'+zIndex+'; \
                        width:'+width+'; \
                        left:0; \
                        top:0; \
                        height:'+height+'; \
                        display:none" src="/js/bck.html"></iframe>').appendTo(document.body || document.documentElement).css('opacity',(o.opacity || .7))
            : $('#sb86backgroundBoardId').css({width:width,height:height});
    return iframe;
}
// 弹窗
function prompt(win){
    var _this = this;
    this.win = win || window;
    this.init = function(content, callback){
        // 开始初始化
        if(!content)
        {
            throw new Error('Argument is invaild');
            return;
        }
        this.callback = callback;
        var content = content,
            getTop = this.win.document.body || this.win.documentElement,
        // 获取容器
            container = typeof content == 'string' ? $(content).hide().appendTo(getTop) :
                (content instanceof jQuery ? content : $(content)).clone(true).hide().appendTo(getTop);
        // 检测容器是否存在。
        if(!container.length) {
            throw new Error('Empty object');
            return;
        }
        // 绑定给对象
        this.container = container;
        return this;
    };
    this.layout = function(callback) {
        if(!this.container){
            throw new Error('Must be init');
            return;
        }
        typeof callback === "function" && callback(this);
        return this;
    };
    this.show = function() {
        // 布局这个浮层的位置。
        var sbs = this.getOffset();
        this.container.css({
            position:'absolute',
            left: sbs.left,
            top: sbs.top,
            display:'block',
            zIndex:1000000
        });
        this.backgroundObj = background({opacity:0.5}).show();
        typeof this.callback === 'function' && this.callback(this);
    };
    this.hide = function(){
        this.container.hide();
        background().hide();
    };
    this.remove = function(){
        this.container && this.container.remove();
        this.container = null;
    };
    // 获取浮动层的偏移量
    this.getOffset = function() {
        var sbs = {}, win = $(_this.win);
        sbs.docWidth = $(_this.win.document.body).width();
        sbs.docHeight = $(_this.win.document.body).height();
       // sbs.docHeight =  window.screen.height;
        sbs.winHeight = win.height();
        sbs.winWidth = win.width();
        sbs.conWidth = $(_this.container).width();
        sbs.conHeight = $(_this.container).height();
        sbs.left = Math.max(0, win.scrollLeft() + (sbs.winWidth) / 2);
        sbs.top = Math.max(0, win.scrollTop() + (sbs.winHeight)/2 );
        // 防止 超出底部
       sbs.top = Math.min(sbs.docHeight - sbs.conHeight-10, sbs.top);
        //sbs.top = 700;
        return sbs;
    };

    // 监控 window 对象的 resize 事件
    $(this.win).resize(function() {
        var sbs = _this.getOffset();
        $(_this.backgroundObj).css({"width":sbs.docWidth+"px", "height":sbs.docHeight+"px"});
        $(_this.container).css({"left": sbs.left+"px", "top": sbs.top+"px"});
    }).scroll(function() {
        var sbs = _this.getOffset();
        $(_this.container).css({"top": sbs.top+"px"});
    });

}
var pop = new prompt();

/*登录*/
function login()
{
    var username = $('#left_login_form input[name=user_name]').val(),password = $('#left_login_form input[name=user_pass]').val(), keep_login = 0;
    var keep_login = 0;
    if($('#rememberMe').prop("checked")  ===true)
    {
        keep_login = 1;
    }
    if(username == '' || $.trim(username) == '请输入用户名'){
        alert('账号不能为空');
        $("#left_login_form input[name=user_name]").focus();
        return;
    }
    if(password == '' || ($.trim(password) == '请输入密码' && password == '')){
        alert('密码不能为空');
        $("#left_login_form input[name=user_pass]").focus();
    }
    if(istrues) {
        istrues = false;
        $.post("/member/dologin", {username: username, password: password,remember:keep_login,_csrf:csrfToken, t: Math.random()}, function (data) {
            istrues = true;
            if(data.status==0)
            {
                $.cookie('udata', data.result['cdatas'], { expires: 7, path: '/' });

                 location.reload();
            }else{
                alert(data.msg);
            }
        }, "json");
    }
}

function dologin()
{
	var html = '<div class="collect1">\
				<div class="unlogin1 askSay">登录<img class="close3" src="../images/close3.png"></div>\
				<form id="left_login_form">\
					<input type="text" placeholder="请输入用户名" name="user_name"/>\
					<input type="password" placeholder="请输入密码" name="user_pass" />\
					<div class="forget">\
						<input type="checkbox" name="rememberMe" id="rememberMe" value="1">自动登录\
						<span><a href="/member/react" target="_blank">忘记密码?</a></span>\
					</div>\
					<a href="javascript:void(0)" onclick="login()">登录</a>\
					<p>还未有账号?<a href="/member/register" target="_blank">立即注册</a></p>\
				</form>\
			</div>';

    pop.init(html,function (o) {

        o.container.find('.close3').click(function () {
            o.remove();
            background().remove();
            return false;
        });
    }).show();
}

/*询价*/
function asks()
{
    var pid = $("#ask-data").attr("data-id"),pname = $("#ask-data").attr("data-title");
    var username = $('#left_xunjia_form input[name=uname]').val(),tel = $('#left_xunjia_form input[name=tel]').val();
    var content = $('#left_xunjia_form .xunjia_content').val();
    if(username == '' || $.trim(username) == '请输入姓名'){
        alert('请输入姓名');
        $("#left_xunjia_form input[name=uname]").focus();
        return;
    }
    if($.trim(username).length<2){
        alert('请输入正确的姓名，谢谢！');
        $("#left_xunjia_form input[name=uname]").focus();
        return;
    }
    if(tel == '' || ($.trim(tel) == '请输入手机号' && tel == '')){
        alert('请输入手机号');
        $("#left_xunjia_form input[name=tel]").focus();
        return;
    }
    if (!tel.match(/^((((13|15|17|14|18)[0-9]{1}))+\d{8})$/))
    {
        alert('手机号格式有误');
        $("#left_xunjia_form input[name=tel]").focus();
        return;
    }
    if(istrues)
    {
        istrues = false;
        $.post("/xunjia/add", {pid: pid, pname: pname,name:username,tel:tel,content:content,_csrf:csrfToken, t: Math.random()}, function (data) {
            istrues = true;
           // alert(data.msg);
        }, "json");
    }

	var url = window.location.href,number = $.trim($("#utel").val()),strurl = url.indexOf('jzl_')!='-1'? url.substr(0, url.indexOf('#jzl_')):url;
	var urls = "/common/calltellinit?m=Backend&c=Sbreg&a=addx&froms=0&sbname="+pname+";"+content+"&utel="+tel+"&uname="+username+"&cip="+cip+"&urlx="+strurl;  
	$.getJSON(urls,function(data){});
	
	
    alert("请耐心等待，尚标顾问会马上电话联系您！");
    $("#uname").val('');
    $("#utel").val('');
    $("#tmmsg").val('');
    return false;
}


function askshow()
{
	var html = '<div class="askShow">\
					<div class="askSay">询价留言<img class="close3" src="../images/close3.png"></div>\
						<form id="left_xunjia_form">\
						联系人<input type="text" placeholder="请输入姓名" name="uname"><br>\
						手机号<input type="text" placeholder="请输入手机号" name="tel"><br>\
						<em>留言内容</em><textarea class="xunjia_content" name="content" cols="30" rows="10" placeholder="请输入留言"></textarea>\
					    <a href="javascript:void(0)" onclick="asks()" class="tosubmit">提交咨询</a>\
					</form>\
				</div>';
    pop.init(html,function (o) {
        o.container.find('.close3').click(function () {
            o.remove();
            background().remove();
            return false;
        });
    }).show();
}

/*收藏*/
function myCollections(data)
{
	var html = '<div class="onlineCon">\
				<div class="unlogin1 askSay online2">加入收藏成功<img class="close3" src="../images/close3.png"></div>\
				<div class="successful">\
					<div>商品收藏成功</div>\
					<a href="/collectionlist.html" target="_blank">查看我的收藏></a>\
				</div>\
				<div class="redation">\
					<h4>为您推荐</h4>\
					<div class="clearfix redCon">';
                    if( data.length>1) {
                        for (var i = 0; i < data.length; i++) {
                            var pic = data[i]['sbpic'];
                            var url = pic.substr(0, 7) === 'http://' ? pic : 'http://www.86sb.com/' + pic;
                            html += '<div>\
							<a href="/info-' + data[i]['id'] + '.html" target="_blank"><img src="' + url + '" width="75" height="55"></a>\
							<p><a  href="/info-' + data[i]['id'] + '.html" target="_blank">' + data[i]['sbname'] + '</a></p>\
						</div>';
                        }
                    }
             html += '</div>\
				</div>\
			</div>';

    pop.init(html,function (o) {
        o.container.find('.close3').click(function () {
            o.remove();
            background().remove();
            return false;
        });
    }).show();
}
/*客服真伪*/
function kefu_t_f()
{
    var html='<div class="pop_verify" style="display: block;"><form id="verifySer">\
                <div class="pop_verify_hd"><span class="fl tit">客服真假验证</span><a class="fr close" href="javascript:;"></a></div>\
                    <div class="pop_verify_bd">\
                        <li>\
                        <input type="text"  placeholder="输入您需要验证的QQ号和手机号" value="" class="inp kefu_word" name="verify" minlength="4" maxlength="15">\
                        </li>\
                        <li>\
                        <input type="button" value="立即验证" class="btn tosu_kefu_submit">\
                        </li>\
                    </div>\
                    <div class="pop_verify_ft">\
                        <p id="verify" class="t1">您验证的号码： <strong>4007110860</strong> 为<em>真客服</em>！</p>\
                        <p class="t2" id="kefuimg"><img src="/img/verify_t.png"/></p>\
                        <p id="verify_1" class="t3">此客服为真客服，请放心交易</p>\
                        <p>如有疑问，请致电客服电话：400-711-0860</p>\
                    </div>\
            </form></div>';

    pop.init(html,function (o) {
        o.container.find('.tosu_kefu_submit').click(function () {
            var str = $('.kefu_word').val(),qq =/^[1-9][0-9]{4,12}$/;
            //var tel =/^((13|4|5|7|8[0-9]{1})+\d{8})$/;
            var tel =/^((1(3|4|5|7|8)[0-9]{1})+\d{8})$/;
            if(!qq.test(str)&&!str.match(tel))
            {
                alert("请输入正确格式的手机号或者QQ");
                return ;
            }
            $.ajax({
                url: "/products/crms",
                type: "POST",
                data: {search_key:str,_csrf:csrfToken, t: Math.random()},
                dataType: "json",
                async: false,
                success: function (data) {
                    $("#verify").find("strong").text(str);
                    $("#verify").find("em").text((data.status == 0)?'真客服':'假客服');
                    if(data.status == 0)
                    {
                        $("#kefuimg").html('<img src="/img/verify_t.png">');
                    }else{
                        $("#kefuimg").html('<img src="/img/verify_f.png">');
                    }

                    $("#verify_1").text((data.status == 0)?'此客服为真客服，请放心交易':'如您在交易中遇到，请立即停止交易');
                },
                error: function () {
                    alert("请求异常！");
                }
            });
        });

        o.container.find('.kefu_word').keyup(function () {
            var str = $(this).val();
            $(this).val(str.replace(/[^\d\.]/g,''));
        });
        o.container.find('.close').click(function () {
            o.remove();
            background().remove();
            return false;
        });
    }).show();
}




function toheart(sid,pname,bigclassid,url,arr,that)
{
    if(islogin)
    {
        /*if(sid==undefined||sid==0||sid==''||sid=='0'){
            alert("请求异常!！");
            return;
        }*/
        if (istrues)
        {

           var method = url.indexOf("collectiondel") != -1 ? 'GET' : 'POST';
            istrues = false;
            $.ajax({
                url: url,
                type: method,
                data: arr,
                dataType: "json",
                async: false,
                success: function (data) {
                    istrues = true;
                    if (data.status == 0) {
                        //alert("恭喜您，收藏成功");
                        if(url.indexOf("collectiondel") != -1){
                            alert("已取消收藏！");
                            that.attr("data-type",0);
                            that.removeClass('selectcollect');
                            that.text("收藏");
                        }else {
                            myCollections(data.result);
                            that.addClass('selectcollect');
                            $(".shou_add").attr("data-type",1);
                            $(".shou_add").attr("style",'color: rgb(200, 1, 1);background: transparent url(../images/redHeart.jpg)  no-repeat scroll 4px center;');
                            $(".shou_add").text("已收藏");
                        }

                    }else{
                        alert(data.msg);
                    }
                },
                error: function () {
                    istrues = true;
                    alert("请求异常！");
                }
            });
        }
    }else{
        dologin();
    }
}



function toshare(sid,pname,bigclassid)
{
    if(islogin)
    {
        if (istrues)
        {
            istrues = false;
            $.ajax({
                url: "/products/addsharer",
                type: "GET",
                data: {pid: sid,bigclassid:bigclassid,pname:pname,_csrf:csrfToken, t: Math.random()},
                dataType: "json",
                async: false,
                success: function (data) {
                    istrues = true;
                    if (data.status == 0) {
                        alert("恭喜您，添加成功");
                    }else{
                        alert(data.msg);
                    }
                },
                error: function () {
                    istrues = true;
                    alert("请求异常！");
                }
            });
        }
    }else{
        dologin();
    }
}
function to_weixinImge(image)
{
    var html = '<div class="askShow" style="width: 308px; height: 360px;">\
					<div class="askSay"><img class="close3" src="../images/close3.png"></div>\
				        <img src="'+image+'" style="width: 304px;">\
				</div>';
    pop.init(html,function (o) {
        o.container.find('.close3').click(function () {
            o.remove();
            background().remove();
            return false;
        });
    }).show();
}




